package cz.khfotbal.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cz.khfotbal.dao.PlayerDao;
import cz.khfotbal.domain.Player;

@Repository
@Transactional
public class PlayerDaoImpl implements PlayerDao {

	@Autowired
	private SessionFactory sessionFactory;

	private Session session;

	public List<Player> findAllPlayers() {
		session = sessionFactory.getCurrentSession();
		List<Player> list = session.createQuery("from Player").list();
		return list;
	}

	public void updatePlayer(Player player) {
		session = sessionFactory.getCurrentSession();
		session.update(player);
	}

	public void deleteTeam(Player player) {
		session = sessionFactory.getCurrentSession();
		session.delete(player);
	}

	public void savePlayer(Player player) {
		session = sessionFactory.getCurrentSession();
		session.saveOrUpdate(player);
	}

}
